import { Observable,interval } from 'rxjs';
import { take,first,last,takeLast } from 'rxjs/operators'

console.log(Date.now());
const observable:Observable<any> = interval(1000);

const observableTake:Observable<any> = observable.pipe(take(5));
const observableFirst:Observable<any> = observable.pipe(first());
const observableLast:Observable<any> = observableTake.pipe(last());
const observableTakeLast:Observable<any> = observableTake.pipe(takeLast(3));//这样写是后三个值同时出来的。

// const observable:Observable<any> = timer(1000); // 1秒钟后发送0后complete
observable.subscribe(
  {
    next:(value:any) => {
      console.log('[1]###next###');
      console.log(Date.now());
      console.log(typeof(value));
      console.log(value);
    },
    complete:() => {
      console.log('[1]###complete###');
    },
    error:(error:any) => {
      console.log('[1]###error###');
      console.log(error);
    }
  }
);

observableTakeLast.subscribe(
  {
    next:(value:any) => {
      console.log('[2]###next###');
      console.log(Date.now());
      console.log(typeof(value));
      console.log(value);
    },
    complete:() => {
      console.log('[2]###complete###');
    },
    error:(error:any) => {
      console.log('[2]###error###');
      console.log(error);
    }
  }
);